import { onUnmounted, ref } from "vue";
/**
 * 获取当前时间钩子函数
 * @returns { object }  nowTime-当前时间
 */
export default function () {
  let nowTime = ref<string>(new Date().toLocaleString());
  let timer = setInterval(() => {
    nowTime.value = new Date().toLocaleString();
  }, 1000);

  // 卸载前销毁定时器
  onUnmounted(() => {
    clearInterval(timer);
    timer = 0;
  })
  return { nowTime };
}